package com.lwq.seata.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwq.seata.entity.TAmount;
import com.lwq.seata.entity.TOrder;
import com.lwq.seata.feign.TestFeignClient;
import com.lwq.seata.mapper.TOrderMapper;
import com.lwq.seata.service.ITOrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 刘文强
 * @since 2021-09-15
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {

    @Autowired
    private TOrderMapper amountMapper;

    @Autowired
    private TestFeignClient testFeignClient;

    @Override
    @Transactional
    @GlobalTransactional
    public void crateOrder(TOrder tOrder) {
        save(tOrder);
        TAmount tAmount = new TAmount();
        tAmount.setUserId(tOrder.getUserId());
        tAmount.setAmount(10L); // 模拟减10元
        testFeignClient.decrementAmount(tAmount);

        int i = 1 /0;
    }
}
